<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <f:metadata>
            <f:event listener="#{visitasController.setSelectedCliente(null)}" type="preRenderComponent" id="fevent"/>
        </f:metadata>          
        <ui:define name="body">
            <h:form id="SigifEventosintListForm">
                <p:breadCrumb>
                    <p:menuitem value="Home" url="#" />
                    <p:menuitem value="Consulta" url="#" />
                    <p:menuitem value="Visitas" url="#" />
                </p:breadCrumb>   
                <p:panel>
                    <p:dataTable id="datalist"
                                 emptyMessage="Nenhum registro localizado"
                                 scrollable="true"
                                 scrollWidth="98%"
                                 widgetVar="FiltroGlobal"
                                 value="#{visitasController.items}" 
                                 var="item"
                                 selectionMode="single" 
                                 selection="#{visitasController.selected}"
                                 paginator="true"
                                 rowKey="#{item.id}"
                                 rows="10"
                                 paginatorPosition="bottom"
                                 rowsPerPageTemplate="10,20,30,40,50">

                        <f:facet name="header">
                            <p:outputPanel>
                                <p:inputText id="globalFilter" style="width:200px;" placeholder=""/>
                                <p:commandButton value="Filtrar" id="withIcon" onclick="PF('FiltroGlobal').filter()" icon="ui-icon-search" />
                                <p:commandButton id="toggler" type="button" value="Colunas" style="float:right" icon="ui-icon-calculator" rendered="false" />
                                <p:columnToggler datasource="datalist" trigger="toggler" />

                                <p:splitButton value="Exportar" icon="ui-icon-disk">
                                    <p:menuitem value="PDF"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="pdf" target="datalist" fileName="Clientes" preProcessor="#{visitasController.preProcessorPDF}" /></p:menuitem>
                                    <p:menuitem value="XLS"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="xls" target="datalist" fileName="Clientes" /></p:menuitem>
                                    <p:menuitem value="CSV"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="csv" target="datalist" fileName="Clientes" /></p:menuitem>    
                                    <p:menuitem value="XML"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="xml" target="datalist" fileName="Clientes" /></p:menuitem>
                                </p:splitButton>
                            </p:outputPanel>
                        </f:facet>   
                        <p:column filterBy="#{item.tbInstCodInstituicao.nomFantasia}" filterMatchMode="contains" style="width:120px;">
                            <f:facet name="header">
                                <h:outputText value="Cliente"/>
                            </f:facet>
                            <h:outputText value="#{item.tbInstCodInstituicao.nomFantasia}"/>
                        </p:column>
                        <p:column filterBy="#{visitasController.customFormatDate(item.dataEntrada)}" filterFunction="#{visitasController.filterByDate}"  filterMatchMode="contains" style="width:180px;">
                            <f:facet name="filter" >
                                 <h:inputHidden />
                            </f:facet>
                            <f:facet name="header">
                                 <h:outputText value="Data Entrada"/><br />
                                 <label style="padding-right: 4px;">De</label>
                                 <p:calendar id="from" pattern="dd/MM/yyyy" mask="99/99/9999" value="#{visitasController.dateFrom}" styleClass="customCalendar">
                                     <p:ajax event="dateSelect" oncomplete="PF('FiltroGlobal').filter()" />
                                     <p:ajax event="change" oncomplete="PF('FiltroGlobal').filter()" />
                                 </p:calendar>
                                 <br /><label style="padding-right: 10px">A&nbsp;</label>
                                 <p:calendar id="to" pattern="dd/MM/yyyy" mask="99/99/9999" value="#{visitasController.dateTo}" styleClass="customCalendar">
                                     <p:ajax event="dateSelect" oncomplete="PF('FiltroGlobal').filter()"/>
                                     <p:ajax event="change" oncomplete="PF('FiltroGlobal').filter()" />
                                 </p:calendar>
                             </f:facet>                            
                            <h:outputText value="#{visitasController.customFormatDate(item.dataEntrada)}" />
                        </p:column>                     
                        <p:column filterBy="#{visitasController.customFormatHour(item.horaEntrada)}" filterMatchMode="contains" style="width:120px;">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListVisitasTitle_horaEntrada}"/>
                            </f:facet>
                            <h:outputText value="#{visitasController.customFormatHour(item.horaEntrada)}" />
                        </p:column>
                        <p:column filterBy="#{visitasController.customFormatDate(item.dataSaida)}" filterFunction="#{visitasController.filterByDateSaida}"  filterMatchMode="contains" style="width:180px;">
                            <f:facet name="filter" >
                                 <h:inputHidden />
                            </f:facet>
                            <f:facet name="header">
                                 <h:outputText value="Data Saída"/><br />
                                 <label style="padding-right: 4px;">De</label>
                                 <p:calendar id="fromSaida" pattern="dd/MM/yyyy" mask="99/99/9999" value="#{visitasController.dateFromSaida}" styleClass="customCalendar">
                                     <p:ajax event="dateSelect" oncomplete="PF('FiltroGlobal').filter()" />
                                     <p:ajax event="change" oncomplete="PF('FiltroGlobal').filter()" />
                                 </p:calendar>
                                 <br /><label style="padding-right: 10px">A&nbsp;</label>
                                 <p:calendar id="toSaida" pattern="dd/MM/yyyy" mask="99/99/9999" value="#{visitasController.dateToSaida}" styleClass="customCalendar">
                                     <p:ajax event="dateSelect" oncomplete="PF('FiltroGlobal').filter()"/>
                                     <p:ajax event="change" oncomplete="PF('FiltroGlobal').filter()" />
                                 </p:calendar>
                             </f:facet>                            
                            <h:outputText value="#{visitasController.customFormatDate(item.dataSaida)}" />
                        </p:column>                     
                        <p:column filterBy="#{visitasController.customFormatHour(item.horaSaida)}" filterMatchMode="contains" style="width:120px;">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListVisitasTitle_horaSaida}"/>
                            </f:facet>
                            <h:outputText value="#{visitasController.customFormatHour(item.horaSaida)}" />
                        </p:column>
                        <p:column filterBy="#{item.cracha}" filterMatchMode="contains" style="width:120px;">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListVisitasTitle_cracha}"/>
                            </f:facet>
                            <h:outputText value="#{item.cracha}"/>
                        </p:column>
                        <p:column filterBy="#{item.finalidadeVisitaId.descricao}" filterMatchMode="contains" style="width:180px;">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListVisitasTitle_finalidadeVisitaId}"/>
                            </f:facet>
                            <h:outputText value="#{item.finalidadeVisitaId.descricao}"/>
                        </p:column>
                        <p:column filterBy="#{visitasController.getFuncionarioNameByCodigo(item.rhTbFuncionarioCodFunc)}" filterMatchMode="contains" style="width:120px;">
                            <f:facet name="header">
                                <h:outputText value="Funcionário"/>
                            </f:facet>
                            <h:outputText value="#{visitasController.getFuncionarioNameByCodigo(item.rhTbFuncionarioCodFunc)}"/>
                        </p:column>                           
                        <p:column filterBy="#{item.observacao}" filterMatchMode="contains" style="width:180px;">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListVisitasTitle_observacao}"/>
                            </f:facet>
                            <h:outputText value="#{item.observacao}"/>
                        </p:column>
                        <f:facet name="footer">    
                            <p:splitButton value="Exportar" icon="ui-icon-disk">
                                <p:menuitem value="PDF"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="pdf" target="datalist" fileName="Clientes" /></p:menuitem>
                                <p:menuitem value="XLS"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="xls" target="datalist" fileName="Clientes" /></p:menuitem>
                                <p:menuitem value="CSV"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="csv" target="datalist" fileName="Clientes" /></p:menuitem>    
                                <p:menuitem value="XML"  icon="ui-icon-close"  ajax="false"><p:dataExporter type="xml" target="datalist" fileName="Clientes" /></p:menuitem>
                            </p:splitButton>
                        </f:facet>                       
                    </p:dataTable>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
